revision:
The property returns the name of a node:
the tagname (in upper case) for element nodes,
the attribute name for attribute nodes,
#text for text nodes,
#comment for comment nodes,
#document for document nodes.
The property is read-only.
Syntax:
element.nodeName or node.nodeName: the tagname (in upper case) for element nodes, the attribute name for attribute nodes, #text for text nodes, #comment for comment nodes, #document for document nodes
property value:
none :
example
The node name of the "prop" element is:
The node name of the body element is:
<div> <p>The node name of the "prop" element is: <span id="prop"></span></p> <p>The node name of the body element is: <span id="prop1"></span></p> </div> <script> let text = document.getElementById("prop").nodeName; document.getElementById("prop").innerHTML = text; let text1 = document.body.nodeName; document.getElementById("prop1").innerHTML = text1; </script>
The node names of the body element's child nodes.
Whitespaces between elements are considered nodes (#text).
<div> <p>The node names of the body element's child nodes.</p> <p>Whitespaces between elements are considered nodes (#text).</p> <!-- This is a comment. --> <div>Comments are considered nodes (#comments).</div> <p id="prop2"></p> </div> <script> const nodes = document.body.childNodes; let text2 = ""; for (let i = 0; i < nodes.length; i++) { text2 += nodes[i].nodeName + " -- "; } document.getElementById("prop2").innerHTML = text2; </script>